package com.firmboy.io_collection.collection;

import com.firmboy.io_collection.bean.HashTableBean;
import com.sun.org.apache.bcel.internal.generic.NEW;
import org.junit.Test;

import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.locks.AbstractQueuedSynchronizer;

/**
 * map的测试类
 *
 * @author firmboy
 * @create 2018-03-19 下午2:59
 **/
public class Map {


    @Test
    public void hashMapTest(){

        HashMap map = new HashMap();

        map.put(new HashEq(),"1");
        map.put(new HashEq(),"2");
        map.put(new HashEq(),"3");
        map.put(new HashEq(),"4");
        map.put(new HashEq(),"5");
        map.put(new HashEq(),"6");
        map.put(new HashEq(),"7");
        map.put(new HashEq(),"8");
        map.put(new HashEq(),"9");
        map.put(new HashEq(),"10");
        map.put(new HashEq(),"11");
        map.put(new HashEq(),"12");
        map.put(new HashEq(),"13");
        map.put(new HashEq(),"14");
    }

    @Test
    public void hashMap(){
        HashMap hashMap = new HashMap();
        //hashMap.put(null,null);
        Object put = hashMap.put("first", "tom");
        Object put1 = hashMap.put("first", "jey");
        System.out.println(put);
        System.out.println(put1);
    }

    @Test
    public void hashTable(){

        Hashtable<String, String> hashtable = new Hashtable<>();

        String put = hashtable.put("first", "tom");
        String put1 = hashtable.put("first", "tom");
        hashtable.put(null,"success");

        System.out.println(put);
        System.out.println(put1);


    }


    @Test
    public void test2(){
        Hashtable hashtable = new Hashtable();

        HashTableBean bea1 = new HashTableBean();
        HashTableBean bean2 = new HashTableBean();

        hashtable.put(bea1,"1");
        hashtable.put(bean2,"2");

        Object o = hashtable.get(bea1);


    }

    @Test
    public void weakHashMap(){
        WeakHashMap hashMap = new WeakHashMap();

        Object put = hashMap.put("test", "tom");
        Object put1 = hashMap.put("test", "jay");
        System.out.println(put);
        System.out.println(put1);

    }


    @Test
    public void treeMapTest(){

        TreeMap treeMap = new TreeMap();
        Object put = treeMap.put("test", "tom");
        Object put1 = treeMap.put("test", "jay");

        System.out.println(put);
        System.out.println(put1);


    }

    @Test
    public void LinkedHashSetTest(){
        LinkedHashMap hashMap = new LinkedHashMap();
        Object put = hashMap.put("test", "tom");
        Object put1 = hashMap.put("test", "jay");

        System.out.println(put);
        System.out.println(put1);

    }

    @Test
    public void ConcurrentHashMapTest(){
        ConcurrentHashMap concurrentHashMap = new ConcurrentHashMap();

        Object put = concurrentHashMap.put("test", "tom");
        Object put1 = concurrentHashMap.put("test", "jay");

        System.out.println(put);
        System.out.println(put1);

    }


    @Test
    public void test5(){
        TreeMap treeMap = new TreeMap();

        treeMap.put("1",null);

    }
}
